package com.HospitalOutpatient.controller;

import com.HospitalOutpatient.annotation.LoginToken;
import com.HospitalOutpatient.entity.Medication;
import com.HospitalOutpatient.service.MedicationService;
import com.HospitalOutpatient.vo.MedicationVo;
import com.HospitalOutpatient.vo.OutpatientValue;
import com.HospitalOutpatient.vo.OutpatientVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/medication")
public class MedicationController {

    @Autowired
    private MedicationService medicationService;

    @LoginToken
    @GetMapping("/getAllMedication")
    public Result getAllMedication(){
        List<Medication> medicationList = medicationService.getAllMedication();
        return new Result(Code.GET_OK,medicationList,"药品信息");
    }
    @LoginToken
    @PostMapping("/addMedication")
    public Result addMedication(@RequestBody Medication medication){
        if(medicationService.addMedication(medication) == false){
            return new Result(Code.SAVE_ERR,null,"添加药品失败");
        }
        return new Result(Code.SAVE_OK,null,"添加药品成功");
    }
    @LoginToken
    @PostMapping("/deleteMedication")
    public Result deleteMedication(@RequestBody Medication medication){
        if(medicationService.deleteMedication(medication.getMedicationId()) == false){
            return new Result(Code.DELETE_ERR,null,"删除药品失败");
        }
        return new Result(Code.DELETE_OK,null,"删除药品成功");
    }
    @LoginToken
    @PostMapping("/getMedicationByName")
    public Result getMedicationByName(@RequestBody Medication medication){
        List<Medication> medicationList = medicationService.getMedicationByName(medication.getMedicationName());
        return new Result(Code.GET_OK,medicationList,"查询药品成功");
    }

    @LoginToken
    @GetMapping("/getChooseMedication")
    public Result getChooseMedication(){
        List<MedicationVo> medicationVoList = medicationService.getMedicationVo();
        return new Result(Code.GET_OK,medicationVoList,"获取开药栏目信息成功");
    }



}
